<?php

class Default_Model_User
{
    protected $_firstname;
    protected $_lastname;
    protected $_sex;
	protected $_language;
	protected $_email;
	protected $_username;
	protected $_password;
    protected $_id;
    protected $_mapper;
	protected $_active;
	protected $_role;

    public function __construct(array $options = null)
    {  	
        if (is_array($options)) {
            $this->setOptions($options);
        }
    }

    public function __set($name, $value)
    {
        $method = 'set' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid user property');
        }
        $this->$method($value);
    }

    public function __get($name)
    {
        $method = 'get' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid user property');
        }
        return $this->$method();
    }

    public function setOptions(array $options)
    {
        $methods = get_class_methods($this);
        foreach ($options as $key => $value) {
            $method = 'set' . ucfirst($key);
            if (in_array($method, $methods)) {
                $this->$method($value);
            }
        }
        return $this;
    }

    public function setFirstname($firstname)
    {
        $this->_firstname = (string) $firstname;
        return $this;
    }

    public function getFirstname()
    {
        return $this->_firstname;
    }

	public function setLastname($lastname)
	{
		$this->_lastname = (string) $lastname;
		return $this;
	}

    public function getLastname()
    {
        return $this->_lastname;
    }

	public function setSex($sex)
	{
		$this->_sex = (string) $sex;
		return $this;
	}

    public function getSex()
    {
        return $this->_sex;
    }

	public function setLanguage($language)
	{
		$this->_language = (string) $language;
		return $this;
	}

    public function getLanguage()
    {
        return $this->_language;
    }

    public function setEmail($email)
    {
        $this->_email = (string) $email;
        return $this;
    }

    public function getEmail()
    {
        return $this->_email;
    }

    public function setUsername($username)
    {
        $this->_username = $username;
        return $this;
    }

    public function getUsername()
    {
        return $this->_username;
    }

    public function setPassword($password)
    {
        $this->_password = $password;
        return $this;
    }

    public function getPassword()
    {
        return $this->_password;
    }

    public function setRole($role)
    {
        $this->_role = $role;
        return $this;
    }

    public function getRole()
    {
        return $this->_role;
    }

    public function setActive($active)
    {
        $this->_active = $active;
        return $this;
    }

    public function getActive()
    {
        return $this->_active;
    }

    public function setId($id)
    {
        $this->_id = (int) $id;
        return $this;
    }

    public function getId()
    {
        return $this->_id;
    }

    public function setMapper($mapper)
    {
        $this->_mapper = $mapper;
        return $this;
    }

    public function getMapper()
    {
        if (null === $this->_mapper) {
            $this->setMapper(new Default_Model_UserMapper());
        }
        return $this->_mapper;
    }

    public function save()
    {
        return $this->getMapper()->save($this);
    }
	
	public function activateUser($data, $userId){
        return $this->getMapper()->activateUser($data, $userId);				
	}
	
	public function usernameExists($username) {
		return $this->getMapper()->usernameExists($username);
	}
	
	public function emailExists($email) {
		return $this->getMapper()->emailExists($email);
	}

	public function numberOfUsers() {
		return $this->getMapper()->numberOfUsers();
	}

/*
    public function find($id)
    {
        $this->getMapper()->find($id, $this);
        return $this;
    }

    public function fetchAll()
    {
        return $this->getMapper()->fetchAll();
    }
*/
}
